window.onload = function () {

    var accountLogin = document.getElementById("accountLogin");
    var telphoneLogin = document.getElementById("telphoneLogin");
    var accountForm = document.getElementById("accountForm");
    var telphoneForm = document.getElementById("telphoneForm");

    //   进入账号登录的页签
    accountLogin.onmouseover = function () {
        accountLogin.style.backgroundColor=" antiquewhite";
        telphoneLogin.style.backgroundColor="white";
        accountForm.style.display = "block";
        telphoneForm.style.display = "none";
    }
    //进入手机号登录的页签
    telphoneLogin.onmouseover = function () {
        telphoneLogin.style.backgroundColor=" antiquewhite";
        accountLogin.style.backgroundColor="white";
        telphoneForm.style.display = "block";
        accountForm.style.display = "none";
    }

    //    账号登录的表单的提交验证
    var btn1 = document.getElementById("btn1");
    btn1.onclick = function () {

        var account = form1.account.value;
        var pwd = form1.pwd.value;
        if (account == "") {
            alert("请输入账号");
            form1.account.focus();
            return;
        }
        if (pwd == "") {
            alert("请输入密码");
            form1.pwd.focus();
            return;
        }
     //把密码进行加密
        form1.pwd.value = hex_md5(pwd);

     //提交表单
        form1.submit();
    }

    //手机登录的表单提交
    var btn3=document.getElementById("btn3");
    btn3.onclick=function () {
        var phone = form2.phone.value;
        var veriCode = form2.veriCode.value;

        if (phone == null) {
            alert("请输入电话号码");
            form2.phone.focus();
            return;
        }
        if (veriCode == null) {
            alert("请输入验证码");
            form2.veriCode.focus();
            return;
        }

        form2.submit();

    }

    //获得验证码的按钮事件
    var btn2=document.getElementById("btn2");
    btn2.onclick=function () {
        var phone = form2.phone.value;
        //判断电话号码是否符合规范（正则表达式）
        //     13890797752 (1 3578 0-9{9})
       // var phoneReg= /^1[3578]\d{9}$/;
       
       if (!(/^1(3|5|7|8)\d{9}$/).test(phone)){
           alert("电话号码格式错误");
           form2.phone.focus();
           return;
       } else {
           //设置电话号码的提交地址
           var url="/javaWeb01/UserPhoneSend?phone="+phone;
           //创建ajax对象
           var request=new XMLHttpRequest();
           //和服务器建立连接
           request.open("GET",url);
           //向服务器发送请求
           request.send(null);
           //判断ajax的状态(5种)
           request.onreadystatechange=function () {
               if (request.readyState==4){
                   if (request.status==200||request.status==304){
                       alert(request.response);
                   }
               }
           }
        }
    }
}